package GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.util.Calendar;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import UserData.User_Management;

public class BarChart extends JPanel {

	private BarChart bc;
	private JPanel panelGraph;
	private JPanel contentPane;
	private Calendar cal;
	private JScrollPane scrollPane;
	private int UserListNumber = User_Management.Get_User_list.size();
	private JCheckBox[] checkBoxFriend;
	private JScrollPane scrollPaneShowFriends;
	private JScrollBar scrollBar;

	int korean = 70;
	int averLateTime;
	int lateTime1;
	int lateTime2;
	int lateTime3;

	int baseline = 260;
	int Yaxis = 50;

	/*
	 * public static void main(String[] args) { EventQueue.invokeLater(new
	 * Runnable() { public void run(){ try{ BarChart frame = new BarChart();
	 * frame.setVisible(true); } catch(Exception e){ e.printStackTrace(); } }
	 * }); }
	 */
	public void initVar() {
		// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 860, 640);
		contentPane = new JPanel();
		// contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		// setContentPane(contentPane);

		contentPane.setBounds(100, 100, 860, 640);
		add(this.contentPane);
		contentPane.setLayout(null);
		cal = Calendar.getInstance();

		this.scrollPaneShowFriends = new JScrollPane();
		this.scrollPaneShowFriends.setBounds(50, 300, 600, 250);
		this.scrollBar = new JScrollBar();

		this.scrollPaneShowFriends.setRowHeaderView(this.scrollBar);

		JPanel panel_1 = new JPanel();
		this.scrollPaneShowFriends.setViewportView(panel_1);
		panel_1.setLayout(null);

		contentPane.add(scrollPaneShowFriends);
		
		checkBoxFriend = new JCheckBox[UserListNumber];
		
		for (int i = 0; i < UserListNumber; i++) {

			checkBoxFriend[i] = new JCheckBox(User_Management.Get_User_list.get(i).getUser_Real_Name());
			checkBoxFriend[i].setBounds(0, 25 * i, 118, 23);
			panel_1.add(checkBoxFriend[i]);

		}

	}

	public BarChart() {
		initVar();
	}

	public void paint(Graphics g) {
		// g.clearRect(0, 0, getWidth(), getHeight());
		g.drawLine(Yaxis, baseline, 600 + Yaxis, baseline);
		for (int cnt = 1; cnt < 11; cnt++) {
			g.drawString(cnt * 10 + "", 25, baseline - 20 * cnt);
			g.drawLine(Yaxis, baseline - 20 * cnt, 600 + Yaxis, baseline - 20
					* cnt);
		}
		g.drawString("over 100", 25, 10);
		g.drawLine(Yaxis, 40, 600 + Yaxis, 40);
		g.drawString("Average Late Time", 80, baseline + 20);
		g.drawString("LateTime1", 200, baseline + 20);
		g.drawString("LateTime2", 300, baseline + 20);
		g.drawString("LateTime3", 400, baseline + 20);
		g.drawLine(Yaxis, 40, Yaxis, baseline);
		g.setColor(Color.RED);
		if (korean > 0)
			g.fillRect(100, baseline - korean * 2, 10, korean * 2);
		if (averLateTime > 0)
			g.fillRect(200, baseline - averLateTime * 2, 10, averLateTime * 2);
		if (lateTime1 > 0)
			g.fillRect(300, baseline - lateTime1 * 2, 10, lateTime1 * 2);
		if (lateTime2 > 0)
			g.fillRect(400, baseline - lateTime2 * 2, 10, lateTime2 * 2);
		if (lateTime3 > 0)
			g.fillRect(500, baseline - lateTime3 * 2, 10, lateTime3 * 2);

		// g.fillRect(x, y, width, height);
	}
}